﻿using System.Collections;
using System.Collections.Generic;
using Framework;

namespace Game.Util
{

    /// <summary>
    /// 可控栈
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ControllableStack<T> : IEnumerable<T>
    {
        public List<T> m_List;

        public int Count => m_List.Count;

        public T this[int index] => m_List[index];
        public ControllableStack()
        {
            m_List = new List<T>();
        }

        public void Push(T item)
        {
            ///扭过来，放在最后面，再扭过来放在最前面
            m_List.Insert(0,item);
        }

        public T Pop()
        {
            if (m_List.Count > 0)
            {
                T item = m_List[0];
                m_List.RemoveAt(0);
                return item;
            }

            throw new GameFrameworkException("ControllableStack，数量不足");
        }

        public void Remove(T item)
        {
            m_List.Remove(item);
        }

        public void RemoveAt(int index)
        {
            m_List.RemoveAt(index);
        }

        public void Clear()
        {
            m_List.Clear();
        }

        public IEnumerator<T> GetEnumerator()
        {
            return m_List.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }

}